<template>
  <div style="background-color: #fdf6ec">
    <!-- 标签区 -->
    <div><NoteTag @getTags="note.noteTag = $event" /></div>
    <!-- 工具栏 -->
    <el-affix :offset="76">
      <div id="editor-toolbar"></div>
       <div>
        <el-button @click="saveNote" class="border-0">保存</el-button>
      </div>
    </el-affix>
    <!-- 编辑区 -->
    <div class="px-5 py-5">
      <!--标题栏  -->
      <div class="shadow-sm">
        <input
          type="text"
          v-model="note.noteName"
          class="note-name px-2 py-3"
          placeholder="请输入标题..."
        />
      </div>
      <!-- 内容输入区 -->
      <div id="editor-container" class="note-content shadow-sm"></div>
    </div>
  </div>
</template>

<script>
import Editor from "@/editor/editor.js";
import NoteTag from "./NoteTag.vue";

export default {
  name: "NoteAdd",
  components: {
    NoteTag,
  },
  data() {
    return {
      editor: null,
      note: {
        noteName: null,
        noteIntro: null,
        noteContent: null,
        noteTag: [],
      },
    };
  },
  //mounted实例加载完成后调用
  mounted() {
    this.editor = new Editor();
    this.editor.init();
  },
  methods: {
    saveNote() {
      this.note.noteIntro = this.editor.getNoteIntro();
      this.note.noteContent = this.editor.getNoteContent();
      console.log(this.note);
      this.$axios.post('/api/space/note/add',this.note)
      .then(response=>{
        console.log(response)
        let data = response.data
        if(data.code == 200){
          this.$router.push("/space/notelist")
        }
        //alert(data.msg)
      })
    },
  },
};
</script>


<style scoped>
.note-name {
  width: 100%;
  border: none;
  outline: none;
  font-size: 2rem;
}

.note-content {
  min-height: 900px;
  background-color: white;
}
</style>
